# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.touch_action import TouchAction

caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "yeshen"
caps["appPackage"] = "com.jifen.qukan"
caps["appActivity"] = "com.jifen.qkbase.main.MainActivity"
caps["autoGrantPermissions"] = "true"
caps["ensureWebviewsHavePages"] = True

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(40)
driver.find_element(by=AppiumBy.ID, value="com.jifen.qukan:id/a9g").click()

# el2 = driver.find_element(by=AppiumBy.ID, value="com.jifen.qukan:id/agm")
# el2.click()

# 弹窗的“先去逛逛”
# 定位元素：by=AppiumBy.ID, value="com.jifen.qukan:id/agm"
#         by=AppiumBy.ID, value="/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.TextView"
TouchAction(driver).long_press(x=100, y=100, duration=1000).move_to().release().perform()
driver.swipe(100, 100, 200, 200)

# 首页——“我的”
el3 = driver.find_element(by=AppiumBy.XPATH, value=
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout[5]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ImageView")
el3.click()
# 文本框锁定
el4 = driver.find_element(by=AppiumBy.ID, value="com.jifen.qukan:id/bk3")
el4.click()
# 传参
el5 = driver.find_element(by=AppiumBy.ID, value="com.jifen.qukan:id/bk3")
el5.send_keys("15964922426")
# “返回”按钮
el6 = driver.find_element(by=AppiumBy.ID, value="com.jifen.qukan:id/lp")
el6.click()

driver.quit()
